import React from 'react';
import {
    View,
    ListView,
    TouchableOpacity,
    StyleSheet,
    Text,
    Alert,
    TextInput,
    Button,
    ScrollView,
    RefreshControl,
    Navigator
} from 'react-native';
import NavigationBar from './NavigationBar'
import Properties from './config/properties'
import * as requestService from './service/request'
import BillList from './BillList'

export default class UserLogin extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            userName: 'gang.gou',
            userPwd: ''
        };

    }
    /** 周期方法 */
    componentDidMount() {

    }
    submitForm = () => {
        let name = this.state.userName;
        let pwd = this.state.userPwd;
        if (name == '') {
            Alert.alert('请输入用户名');
            return;
        }

        if (pwd == '') {
            Alert.alert('请输入密码');
            return;
        }

        if(name != 'gang.gou'){
            Alert.alert('该用户不存在');
            return;
        }
        if(pwd != 'nicaiya'){
            Alert.alert('密码不正确');
            return;
        }
        const { navigator } = this.props;
         if (navigator) {
            navigator.push({
                name: 'BillList',
                component: BillList,
            })
        }
        /**
         * let userLongUri = Properties['user']['user_login_uri']
          *requestService.post(userLongUri, JSON.stringify(this.state)).then((responseData) => {
          *   alert(responseData.msg);
          *});
          */

    }

    render() {
        return (
            <View>
                <View style={styles.item}>
                    <View style={styles.name_view}>
                        <Text style={styles.name_text} >用户名:</Text>
                    </View>
                    <View style={styles.input}>
                        <TextInput value="gang.gou" onChangeText={(val) => this.setState({ userName: val })}></TextInput>
                    </View>
                </View>
                <View style={styles.item}>
                    <View style={styles.name_view}>
                        <Text style={styles.name_text} >密 码:</Text>
                    </View>
                    <View style={styles.input}>
                        <TextInput secureTextEntry={true} onChangeText={(val) => this.setState({ userPwd: val })}></TextInput>
                    </View>
                </View>
                <View style={[styles.item, styles.submit]}>

                    <View style={styles.input}>
                        <Button title="登录" onPress={this.submitForm}></Button>
                    </View>
                </View>
            </View>
        );
    }

}

var styles = StyleSheet.create({
    name_view: {
        width: 80,
    },
    name_text: {
        fontSize: 20,
        textAlign: 'center',
    },
    submit: {
        marginTop: 40,
        marginLeft: 10,
        marginRight: 10,
    },
    input: {
        flex: 1,
    },
    item: {
        //flex: 1,
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
    }
});